package org.zuel.lkq.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Gongjc
 * @Date: 2020/11/27
 * @Version: 1.0.0
 */
public class ResponseUtil {

    public static Object ok() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", "成功");
        return obj;
    }

    public static Object ok(String msg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("message", msg);
        return obj;
    }

    public static Object ok(Object data) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", "成功");
        obj.put("data", data);
        return obj;
    }

    public static Object ok(long total, List list) {
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", list);
        return ok(data);
    }

    public static Object ok(String errmsg, Object data) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", errmsg);
        obj.put("data", data);
        return obj;
    }

    public static Object fail() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", -1);
        obj.put("errmsg", "错误");
        return obj;
    }

    public static Object fail(int errno, String errmsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("errmsg", errmsg);
        return obj;
    }

    public static Object fail(String errno, String errmsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("errmsg", errmsg);
        return obj;
    }

    public static Object unlogin() {
        return fail(501, "认证失败，请重新登录");
    }

    public static Object serious() {
        return fail(502, "系统内部错误");
    }

    public static Object badArgument() {
        return fail(503, "参数不对");
    }

    public static Object badArgumentValue() {
        return fail(504, "参数值不对");
    }

    public static Object nullArgument() {return fail(518, "传入的参数值为空！请重试！"); }

    public static Object unsupport() {
        return fail(505, "业务不支持");
    }

    public static Object unauthz() {
        return fail(506, "无操作权限");
    }

    public static Object dataNotExist() {
        return fail(507, "记录不存在.");
    }

    public static Object addDataFailed() {
        return fail(508, "添加记录失败.");
    }

    public static Object updatedDataFailed() {
        return fail(509, "更新数据失败");
    }

    public static Object primaryKeyInvalid() {
        return fail(510, "主键不能为空");
    }

    public static Object queryDataFailed() {
        return fail(511, "查看记录失败");
    }

    public static Object updatedDateExpired() {
        return fail(512, "更新数据已经失效");
    }

    public static Object dataExists() {
        return fail(513, "同名数据已存在");
    }


    public static Object dataItemExists() {
        return fail(514, "同名明细已存在");
    }

    public static Object badItemArgument() {
        return fail(515, "明细参数不对");
    }

    public static Object codeOutTime() { return fail(516, "验证码已过期"); }

    public static Object codeError() { return fail(517, "验证码错误"); }

}
